const path = require('path'),
    webpack = require("webpack")
HtmlWebpackPlugin = require('html-webpack-plugin'),
    chalk = require('chalk'),
    log = console.log;
    // readEnv = require(path.resolve(__dirname, './readEnv'));

module.exports = (env) => {

    // let DefineVar = readEnv(`../.env.${env}.json`);
    // log(DefineVar)
    return {
        mode: "development",
        entry: path.resolve(__dirname, '../src/main.js'),
        output: {

            filename: 'main.js',
            path: path.resolve(__dirname, '../dist')
        },
        module: {
            rules: [{
                test: /\.css$/i,
                use: ["style-loader", "css-loader"],
            }, {
                test: /\.less$/i,
                use: [{
                        loader: "style-loader",
                    },
                    {
                        loader: "css-loader",
                    },
                    {
                        loader: "less-loader",

                    },
                ],
            }, {
                test: /\.jsx?$/,
                exclude: /(node_modules|bower_components)/,
                use: {
                    loader: 'babel-loader',
                    options: {
                        presets: ['@babel/preset-env', '@babel/preset-react'],
                        plugins: [
                            "@babel/plugin-proposal-class-properties",
                        ]
                    }
                }
            }, {
                test: /\.(png|jpe?g|gif)$/i,
                use: [{
                    loader: 'file-loader',
                }]
            }]
        },
        plugins: [new HtmlWebpackPlugin({
            title: "singePage",
            filename: 'index.html',
            template: path.resolve(__dirname, '../public/index.html')
        }), new webpack.DefinePlugin({
            process: {}
        })],
        resolve: {
            alias: {
                '@img': path.resolve(__dirname, '../src/images'),
                '@layout': path.resolve(__dirname, '../src/layout'),
                '@redux': path.resolve(__dirname, '../src/redux'),
                '@router': path.resolve(__dirname, '../src/router'),
                '@views': path.resolve(__dirname, '../src/views'),
            },
        },
        devServer: {
            https: true,
            contentBase: path.join(__dirname, '../public'), //告诉服务器内容的来源。仅在需要提供静态文件时才进行配置。
            historyApiFallback: true, //当使用 HTML5 History API 时, 所有的 404 请求都会响应 index.html 的内容
            overlay: { //出现编译器错误或警告时，在浏览器中显示全屏覆盖
                warnings: true,
                errors: true,
            },

        }

    }

};